package jsqlite;

import java.io.PrintWriter;

/* JADX INFO: Access modifiers changed from: package-private */
/* compiled from: Shell.java */
/* loaded from: classes2.dex */
public class DBDump implements Callback {
    Shell s;

    @Override // jsqlite.Callback
    public void columns(String[] strArr) {
    }

    @Override // jsqlite.Callback
    public void types(String[] strArr) {
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public DBDump(Shell shell, String[] strArr) {
        this.s = shell;
        shell.pw.println("BEGIN TRANSACTION;");
        if (strArr == null || strArr.length == 0) {
            try {
                shell.db.exec("SELECT name, type, sql FROM sqlite_master WHERE type!='meta' AND sql NOT NULL ORDER BY substr(type,2,1), name", this);
            } catch (Exception e) {
                shell.err.println("SQL Error: " + e);
                shell.err.flush();
            }
        } else {
            String[] strArr2 = new String[1];
            for (String str : strArr) {
                strArr2[0] = str;
                try {
                    shell.db.exec("SELECT name, type, sql FROM sqlite_master WHERE tbl_name LIKE '%q' AND type!='meta'  AND sql NOT NULL  ORDER BY substr(type,2,1), name", this, strArr2);
                } catch (Exception e2) {
                    shell.err.println("SQL Error: " + e2);
                    shell.err.flush();
                }
            }
        }
        shell.pw.println("COMMIT;");
    }

    @Override // jsqlite.Callback
    public boolean newrow(String[] strArr) {
        if (strArr.length != 3) {
            return true;
        }
        PrintWriter printWriter = this.s.pw;
        printWriter.println(String.valueOf(strArr[2]) + ";");
        if (strArr[1].compareTo("table") == 0) {
            Shell shell = (Shell) this.s.clone();
            shell.mode = 5;
            shell.set_table_name(strArr[0]);
            String[] strArr2 = {strArr[0]};
            try {
                String str = "SELECT * from '%q'";
                if (shell.db.is3()) {
                    TableResult tableResult = shell.db.get_table("PRAGMA table_info('%q')", strArr2);
                    if (tableResult != null) {
                        StringBuffer stringBuffer = new StringBuffer();
                        String str2 = "";
                        stringBuffer.append("SELECT ");
                        for (int i = 0; i < tableResult.nrows; i++) {
                            String str3 = ((String[]) tableResult.rows.elementAt(i))[1];
                            stringBuffer.append(str2 + "quote(" + Shell.sql_quote_dbl(str3) + ")");
                            str2 = ",";
                        }
                        stringBuffer.append(" from '%q'");
                        str = stringBuffer.toString();
                        shell.mode = 6;
                    }
                    shell.db.exec(str, shell, strArr2);
                } else {
                    shell.db.exec("SELECT * from '%q'", shell, strArr2);
                }
            } catch (Exception e) {
                PrintWriter printWriter2 = this.s.err;
                printWriter2.println("SQL Error: " + e);
                this.s.err.flush();
                return true;
            }
        }
        return false;
    }
}
